using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace Rensselaer_Event_Finder
{
    public partial class AllVenuesMDI : Form
    {

        #region Public Methods

        public AllVenuesMDI()
        {
            InitializeComponent();
        }

        

        /// <summary>
        /// Load all the venues in the given category.
        /// </summary>
        /// <param name="categoryID">Category id to load. (-1 = all categories)</param>
        public void load_venues(int categoryID)
        {
            //clear old venues
            clearLocations();
            if (categoryID != -1)
            {
                foreach (Panel newPan in MainForm.allVenues)
                {
                    IList<Category> panCat = (IList<Category>)newPan.Tag;
                    bool catMatch = false;
                    foreach (Category cat in panCat)
                    {
                        if (cat.Id == categoryID)
                            catMatch = true;
                    }
                    if (catMatch)
                        this.layoutPanel.Controls.Add(newPan);
                }
            }
            else
            {
                foreach (Panel newPan in MainForm.allVenues)
                {
                    this.layoutPanel.Controls.Add(newPan);
                }
            }

        }

        public void display_venues(IList<Location> venuesList)
        {
            clearLocations();
            //add each new location
            foreach (Location newloc in venuesList)
            {
                this.layoutPanel.Controls.Add(MainForm.Create_Loc_Panel(newloc));
            }
        }

        public void clearLocations()
        {
            layoutPanel.Controls.Clear();
        }

        #endregion

        #region Event Handlers

        public void newWebsiteLink_Click(object sender, EventArgs e)
        {
            string url = ((LinkLabel)sender).Text;
            if (url.StartsWith("www."))
            {
                url = "www." + url;
            }

            System.Diagnostics.Process.Start(url);
        }


        public void VenueName_Click(object sender, EventArgs e)
        {
            //load the venue corresponding to the id in the tag, show that venue in the VenueMDI
            LinkLabel senderLink = (LinkLabel)sender;
            Location loadLoc = Globals.getLocationService().getById((int)senderLink.Tag);
            MainForm.venueFrm.load_venue(loadLoc);
            MainForm.SelectMDIForm(MainForm.venueFrm);
        }

        private void homeBtn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MainForm.SelectMDIForm(MainForm.homeFrm);
        }


        #endregion

    }
}